package com.zerui.manager.app.accessauthdevice.scheduler;

import com.zerui.manager.app.accessauthdevice.executer.AccessAuthDeviceSyncCmdExe;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @Author wh
 * @create_time 2023-08-23 15:33
 *
 * 同步设备管理 - 门禁相关设备
 */
@Slf4j
@Component
public class AccessAuthDeviceInitScheduler{

    @Resource
    private AccessAuthDeviceSyncCmdExe accessAuthDeviceSyncCmdExe;

    @EventListener(ContextRefreshedEvent.class)
    public void initDevice(){
        deviceSync();
    }

    @Scheduled(initialDelay=1000*30,fixedRate=1000*60*60)
    private void syncDataScheduler() {
        deviceSync();
    }

    private void deviceSync(){
        log.info("sync access auth device start:{}", LocalDateTime.now());
        accessAuthDeviceSyncCmdExe.execute();
        log.info("sync access auth device end:{}", LocalDateTime.now());
    }
}
